package com.kitty.web.controller;

import com.kitty.web.controller.BaseController;
import com.kitty.web.common.AjaxResult;
import com.kitty.web.core.page.TableDataInfo;
import com.kitty.web.domain.PNpc;
import com.kitty.web.system.npc.service.IPNpcService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * NPC配置Controller
 * 
 * @author soul
 * @date 2022-03-10
 */
@Controller
@RequestMapping("/system/npc")
public class PNpcController extends BaseController
{
    private String prefix = "system/npc";

    @Autowired
    private IPNpcService pNpcService;


    @GetMapping()
    public String npc()
    {
        return prefix + "/npc";
    }

    /**
     * 查询NPC配置列表
     */

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PNpc pNpc)
    {
        startPage();
        List<PNpc> list = pNpcService.selectPNpcList(pNpc);
        return getDataTable(list);
    }


    /**
     * 新增NPC配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存NPC配置
     */

    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PNpc pNpc)
    {
        return toAjax(pNpcService.insertPNpc(pNpc));
    }

    /**
     * 修改NPC配置
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PNpc pNpc = pNpcService.selectPNpcById(id);
        mmap.put("pNpc", pNpc);
        return prefix + "/edit";
    }

    /**
     * 修改保存NPC配置
     */

    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PNpc pNpc)
    {
        return toAjax(pNpcService.updatePNpc(pNpc));
    }

    /**
     * 删除NPC配置
     */

    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(pNpcService.deletePNpcByIds(ids));
    }
}
